package vn.vos.model;

import java.net.MalformedURLException;
import java.rmi.RemoteException;
import java.util.Vector;

import org.apache.axis.client.Call;

public class JavaWebserviceCaller {
	public String callWebService(String endpoint, String namespace, 
			String operation, Object[] params) throws MalformedURLException, RemoteException {
		 Call call = new Call(endpoint);
	     call.setOperationName(new javax.xml.namespace.QName(namespace, operation));  
	     call.setUseSOAPAction(true);
	     call.setSOAPActionURI("");
	     call.setEncodingStyle(null);
	     call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
	     call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
	     call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);

		 try {   	    	
		  	java.lang.Object _resp = call.invoke(params);	
		    if (_resp instanceof java.rmi.RemoteException) {
		        throw (java.rmi.RemoteException)_resp;
		    } else {
		         try {
		              return (java.lang.String) _resp;
		         } catch (java.lang.Exception _exception) {
		             return (java.lang.String) org.apache.axis.utils.JavaUtils.convert(_resp, java.lang.String.class);
		         }
		      }
		  } catch (org.apache.axis.AxisFault axisFaultException) {
		      throw axisFaultException;
		  }
	}
	
	public static void main( String args[] ) throws MalformedURLException, RemoteException {
		JavaWebserviceCaller caller = new JavaWebserviceCaller();
		String endpoint = "http://localhost:8080/WebService4/services/Hello";
		String namespace = "http://vn.vos";
		String operation = "sayHello";
		Object[] params = new Object[]{"tu"};
		
		System.out.println(caller.callWebService(endpoint, namespace,operation, params));
	}
}
